package com.bb.blog.activiti.controller.query;

import com.bb.blog.activiti.domain.dto.UserTaskObj;
import com.bb.blog.activiti.domain.param.QueryUserTaskParam;
import lombok.RequiredArgsConstructor;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * UserTask
 */

@RestController
@RequestMapping("/userTask")
@RequiredArgsConstructor
public class UserTaskController {
    private final TaskService taskService;

    @GetMapping("/list")
    public Object taskList(@Validated QueryUserTaskParam queryParam) {
        List<Task> list = taskService.createTaskQuery().processInstanceId(queryParam.getProcessInstanceId()).list();
        List<UserTaskObj> taskObjList = list.stream().map(task -> {
            UserTaskObj userTask = new UserTaskObj();
            BeanUtils.copyProperties(task, userTask);
            return userTask;
        }).collect(Collectors.toList());

        return taskObjList;

    }

}
